<?php

namespace App\Models\Goods;

use App\Models\Cart\SpecGoods;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Goods extends Model
{
    use HasFactory;

    /**
     * 一对一hasOne
     * 一个商品对应一个分类
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function type(){
        return $this->hasOne(Type::class,'id','cate_id')->bind(['cate_name']);
    }

    /**
     * belongsTo
     * 一个商品对应一个品牌
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function brand(){
        return $this->belongsTo(Brand::class,'id','cate_id');
    }

    /**
     * 一个商品对应多张图片
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function image(){
        return $this->hasMany(GoodsImages::class,'goods_id','id');
    }

    /**
     * 一个商品对应多个sku
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function sku(){
        return $this->hasMany(SpecGoods::class,'goods_id','id');
    }
}
